#lang rosetta-racket


(provide move-inc
         vector-set
         vector-set-vals
         cross2
         cross-area
         cross-volume
         world-cs<-brick-cs)


(define (move-inc move-fn s shapes)
  (map
   call
   (map (cλ cλ move-fn) (: < 0 .. s .. < (length shapes) > >))
   shapes))

(define move-x-inc (cλ move-inc move-x))
(define move-y-inc (cλ move-inc move-y))
(define move-z-inc (cλ move-inc move-z))

(define (vector-set vec pos val)
  (let ((vec2 (vector-copy vec)))
    (vector-set! vec2 pos val)
    vec2))

(define (vector-set-vals vec poss vals)
  (let ((vec2 (vector-copy vec)))
    (for ((pos poss) (val vals))
      (vector-set! vec2 pos val))
    vec2))

(define (cross2 lst1 lst2)
  (append*
   (for/list ((i lst1))
     (for/list ((j lst2))
       (list i j)))))

(define (cross3 lst1 lst2 lst3)
  (append*
   (append*
    (for/list ((i lst1))
      (for/list ((j lst2))
        (for/list ((k lst2))
          (list i j k)))))))

(define (cross-area p size)
  (cross2
   (: < (xyz-x p) .. < (xyz-x size) > >)
   (: < (xyz-y p) .. < (xyz-y size) > >)))

(define (cross-volume p size)
  (cross3
   (: < (xyz-x p) .. < (xyz-x size) > >)
   (: < (xyz-y p) .. < (xyz-y size) > >)
   (: < (xyz-z p) .. < (xyz-z size) > >)))

(define (world-cs<-brick-cs p world-cs brick-cs)
  (+c world-cs brick-cs p))